package Strategy;

import Adaptor.A_Changle;
import InterfaceClient.IChat;
import Packets.pkValue;
import StaticClass.ArrSocket;
import ThreadClient.ThreadMain;
//import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Oho
 */
public class A_Interface {
    //kiem tra xem co ton tai jframe nao co chat hok 
    ObjectInputStream in;
    ObjectOutputStream out;
    SIPack part;
    //JFrame f ;
    public  A_Interface(ObjectInputStream in ,ObjectOutputStream out)
    {
        this.in = in;
        this.out = out;
        
    }

   
    public void setSIPart(int type) {
        if (type == 1) {
            part = new SI_Chat();
            //f= new IChat();
        }
        if (type == 2) {
            //viet ham trong nay de goi lai dong thoi tao class moi implement lai 2 phuong thuc cua SIPart
        }
    }

    public void Check(pkValue pk, String value, Socket sk) {
        //   JFrame f = new IChat()instanceof IChat;
        //la loai tin gi 
            setSIPart(1);
            if (value.compareTo("READ") == 0) {
                try {
                    pk = (pkValue) in.readObject();
                 
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(A_Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(A_Interface.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    
                }
            }
        
        if (value.compareTo("WRITE") == 0) {
            try {
//                ObjectOutputStream out= new ObjectOutputStream(sk.getOutputStream());
                //ObjectOutputStream out =new ObjectOutputStream( sk.getOutputStream());

                out.writeObject(pk);
                out.flush();
                
               // setSIPart(1);
                  //  part =  new SI_Chat();
                   // part.check(vl, sk);
                  //  part.ConvertPackage(pk, f, "Client :");
            //    System.out.println("Client :  " + pk.getObj());
            //    ArrSocket.  ic.txtInput.append("Client : " +pk.getObj()+"\n");
               // out=null;
            } catch (IOException ex) {
                Logger.getLogger(A_Interface.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

         part.check(pk, sk);

    }
}

